<?php
/**
 * Created by PhpStorm.
 * User: henry
 * Date: 2017/2/23
 * Time: 上午10:14
 */

namespace business\base\models;


use yii\db\ActiveRecord;

class BaseActiveRecord extends ActiveRecord
{

    public static function getDb()
    {
        return \Yii::$app->db;
    }

    /**
     * @var array 字段别名
     */
    public $_fieldsAlias = [];

    public function __get($name)
    {
        $attributeName = $name;
        if (isset($this->_fieldsAlias[$name])) {
            $attributeName = $this->_fieldsAlias[$name];
        }
        return parent::__get($attributeName);
    }

    public function __set($name, $value)
    {
        $attributeName = $name;
        if (isset($this->_fieldsAlias[$name])) {
            $attributeName = $this->_fieldsAlias[$name];
        }
        parent::__set($attributeName, $value);
    }
}